package com.zhangdi.dwperms.controller;

import com.zhangdi.dwcommons.response.Response;
import com.zhangdi.dwcommons.response.ResponseUtil;
import com.zhangdi.dwperms.entity.Account;
import com.zhangdi.dwperms.enums.LoginType;
import com.zhangdi.dwperms.request.LoginRequest;
import com.zhangdi.dwperms.service.AccountService;
import com.zhangdi.dwperms.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by zhangdi on 2020/01/13 17:27:48.
 */

@RestController
public class TestController {
    @Autowired
    AccountService accountService;

    @Autowired
    MenuService menuService;

    @GetMapping("/wx/login")
    public Response testJWT_WX(String code, ServletResponse response) {
        LoginRequest request = new LoginRequest();
        request.setType(LoginType.wx);
        request.setCode(code);
        return accountService.login(request, (HttpServletResponse)response);
    }

    @GetMapping("/t1/test")
    public Response test() {
        return ResponseUtil.success(111);
    }

    @GetMapping("/t1/test2")
    public Response test2() {
        return ResponseUtil.success("test2");
    }

    @GetMapping("/test3")
    public Response test3() {
        return ResponseUtil.success("test3");
    }

    @GetMapping("/test1/test2")
    public Response test1_2() {
        return ResponseUtil.success(menuService.findUserAllPermissions(10L));
    }

    @GetMapping("/test1/test1")
    public Response<String> test1_1() {
        return ResponseUtil.success("这是test1");
    }
}
